extends Button

export var sl=32
export var pp=Vector2(-32,16)
export var u=0.2
export var movable=false
var op
var e

func init():
	self.connect("focus_entered",self,"fen")
	self.connect("focus_exited",self,"fex")
	self.connect("mouse_entered",self,"fen")
	self.connect("mouse_exited",self,"fex")
	op=rect_position.x
	e=op
	movable=true

func _ready():
	init()

func fen():
	if(movable):
		e=op+sl
		sp()

func sp():
	if(get_parent().is_class("Node2D")):
		sys.pointer.e=Vector2(e+get_parent().global_position.x,rect_global_position.y)+pp
	elif(get_parent().is_class("Control")):
		sys.pointer.e=Vector2(e+get_parent().rect_global_position.x,rect_global_position.y)+pp
	else:
		sys.pointer.e=Vector2(e,rect_global_position.y)+pp

func fex():
	if(movable):
		e=op
		sp()

func _process(delta):
	if(movable):
		if(get_parent().is_class("Node2D")):
			if(rect_global_position.x!=e+get_parent().global_position.x):
				rect_global_position.x=lerp(rect_global_position.x,e+get_parent().global_position.x,u)
		elif(get_parent().is_class("Control")):
			if(rect_global_position.x!=e+get_parent().rect_global_position.x):
				rect_global_position.x=lerp(rect_global_position.x,e+get_parent().rect_global_position.x,u)
		else:
			if(rect_global_position.x!=e):
				rect_global_position.x=lerp(rect_global_position.x,e,u)
